//
//  RootViewController.m
//  UI豆瓣2015到2016跨年作业
//
//  Created by LHY on 15/12/31.
//  Copyright © 2015年 Lanou 32 李昊宇. All rights reserved.
//

#import "RootViewController.h"
#import "ActivityModel.h"
#import "OneTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "ScrollViewController.h"
@interface RootViewController ()<UITableViewDataSource, UITableViewDelegate>


@property (nonatomic , retain) UITableView *tableView;
@property (nonatomic , retain) NSMutableArray *arrModel;


@end




@implementation RootViewController

- (void)dealloc
{
    [_tableView release];
    [_arrModel release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.5 alpha:1];
    self.navigationItem.title = @"活动";
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:(UITableViewStylePlain)];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    
    [self Data];
    
    [_tableView registerClass:[OneTableViewCell class] forCellReuseIdentifier:@"cell"];





}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 200;


}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _arrModel.count;
    
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    OneTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    ActivityModel *actt = _arrModel[indexPath.row];
    cell.titleLabel.text = actt.title;
    NSString *str = [NSString stringWithFormat:@"%@", [actt.begin_time substringFromIndex:5] ];
    NSString *str1 = [NSString stringWithFormat:@"%@", [actt.end_time substringFromIndex:5]];
    cell.timeLabel.text = [NSString stringWithFormat:@"%@--%@", str,str1];
    cell.addressLabel.text = actt.address;
    cell.participantLabel.text = [NSString stringWithFormat:@"%@", actt.participant_count];
    cell.wisherLabel.text = [NSString stringWithFormat:@"%@", actt.wisher_count];
    cell.categoryLabel.text = actt.category_name;
    [cell.Iv sd_setImageWithURL:[NSURL URLWithString:actt.image]];
    
    
    return cell;
}


- (void)Data{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"activity" ofType:@"plist"];
    NSArray * arrData = [NSArray arrayWithContentsOfFile:path];
    self.arrModel = [NSMutableArray array];
    for (NSDictionary *dic in arrData) {
        ActivityModel *ac = [ActivityModel activityModel];
        [ac setValuesForKeysWithDictionary:dic];
        [_arrModel addObject:ac];
    }




}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

      
    ScrollViewController *scc = [[ScrollViewController alloc] init];
    
    ActivityModel *ac = _arrModel[indexPath.row];
    scc.str = ac.title;
    
    scc.indexPath = indexPath;
    scc.arrModel = _arrModel;

    [self.navigationController pushViewController:scc animated:YES];
    [scc release];


}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
